
<!DOCTYPE html>
<html style="overflow-x: hidden; overflow-y: auto;">
<head>
<title>角色管理</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
[#include "/admin/include/header.htm"]
<link
	href="${base}/static/plugin/jquery-ztree/3.5.12/css/zTreeStyle/zTreeStyle.min.css"
	rel="stylesheet" type="text/css" />
<script
	src="${base}/static/plugin/jquery-ztree/3.5.12/js/jquery.ztree.core-3.5.min.js"
	type="text/javascript"></script>
<script
	src="${base}/static/plugin/jquery-ztree/3.5.12/js/jquery.ztree.excheck-3.5.min.js"
	type="text/javascript"></script>
<script type="text/javascript">
	$(document)
			.ready(
					function() {
						$("#name").focus();
						$("#inputForm")
								.validate(
										{
											rules : {
												roleName : {
													remote : "/admin/role/checkRoleName?oldRoleName="
															+ encodeURIComponent("")
												}
											},
											messages : {
												roleName : {
													remote : "角色名已存在"
												}
											},
											submitHandler : function(form) {
												var ids = [], nodes = tree .getCheckedNodes(true);
												for (var i = 0; i < nodes.length; i++) {
													ids.push(nodes[i].id);
												}
												$("#menuIds").val(ids);
												 layer.load(0,{share:false});
												form.submit();
											}
										});

						var setting = {
							check : {
								enable : true,
								nocheckInherit : true
							},
							view : {
								selectedMulti : false
							},
							data : {
								simpleData : {
									enable : true
								}
							},
							callback : {
								beforeClick : function(id, node) {
									tree.checkNode(node, !node.checked, true,
											true);
									return false;
								}
							}
						};
						// 用户-菜单
						var zNodes = [ 
						              [#if allMenuList as m]
						              	[#if m_index==0]
						          			{ id : "${m.menuId}", pId : "${m.pid!'0'}", name : "${m.menuName!}" }
						              	[#else]
						              		, { id : "${m.menuId}", pId : "${m.pid!'0'}", name : "${m.menuName!}" }
						              	[/#if]
						              [/#if]
									];
						// 初始化树结构
						var tree = $.fn.zTree.init($("#menuTree"), setting,
								zNodes);
						// 默认选择节点
						var ids = "".split(",");
						for (var i = 0; i < ids.length; i++) {
							var node = tree.getNodeByParam("id", ids[i]);
							try {
								tree.checkNode(node, true, false);
							} catch (e) {
							}
						}
						// 默认展开全部节点
						tree.expandAll(true);

					});
</script>

</head>
<body>

	<ul class="nav nav-tabs">
		<li><a href="/admin/role/list">角色列表</a></li>
		<li class="active"><a href="/admin/role/add">角色添加</a></li>
	</ul>
	<br />

	<form id="inputForm" class="form-horizontal" action="save"
		method="post">
		<input id="id" name="id" type="hidden" value="" />
		<script type="text/javascript">
			top.$.jBox.closeTip();
		</script>
		<div class="control-group">
			<label class="control-label"><span style="color: red;">*</span>角色名称:</label>
			<div class="controls">
				<input id="roleName" name="roleName" class="required" type="text" value="" minlength="2" maxlength="50" /> <span class="help-inline">角色名称建议语义明确</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">角色授权:</label>
			<div class="controls">
				<div id="menuTree" class="ztree" style="margin-top: 3px; float: left;"></div>
				<input id="menuIds" name="menuIds" type="hidden" value="" />
			</div>
		</div>
		<div class="form-actions">
			<input id="btnSubmit" class="btn btn-primary" type="submit"
				value="保 存" />&nbsp; <input id="btnCancel" class="btn" type="button"
				value="返 回" onclick="history.go(-1)" />
		</div>
	</form>

</body>
</html>
